//var site="http://114.116.30.154:8680";
//var site="http://aux-ui.happygroup2015.com";
var site="http://49.4.2.133:30875";
$(document).ready(function() {
	refresh();
	
	$("#add_button").click(function(){
		addNew();
	});
	
	$("#refresh_button").click(function(){
		refresh();
	});
	
});

function refresh()
{
	$('#list').empty();
	$.get(site+"/user/list",function(r) {
		console.log(r);
		r=$.parseJSON(r);
		for (var i = 0; i < r.length; i++) {
			$('#list').prepend('<tr><td>'+r[i].id+'</td><td>'+r[i].account+'</td><td><a class="delete_button" user_id="'+r[i].id+'"  href="#">删除</a></td></tr>');
		}
		$('#list').prepend('<tr><td width="200">ID</td><td>NAME</td><td width="100">&nbsp;</td></tr>');
		
		
		$(".delete_button").click(function(r){
			var el=$(r.target);
			var id=el.attr("user_id");
			alert(id)
			deleUser(id);
		});
		
	});
	
	
}

function deleUser(id)
{ 
	$.get(site+"/user/delete?id="+id,function(r) {
		refresh();
	});
}

function addNew()
{ 
	$.get(site+"/user/create?acount=leefj&passwd=999",function(r) {
		refresh();
	});
}



